// pages/college/collegeDetail/collegeDetail.js
var wxCharts = require('../../../utils/wxcharts.js');
var app = getApp();
var daylineChart = null;
var yuelineChart = null;

Page({
  data: {
    navTab: ["招生简章", "考研分数线", "考研报录比"],
    currentNavtab: "0",
    
    // 计科历年分数线
    jkGradeData:[355, 275, 290, 265, 280],
    // 软工历年分数线
    rgGradeData:[355, 275, 290, 265, 280],
    // 电子历年分数线
    dzGradeData:[355, 275, 290, 265, 280],

    // 计科报录比
    jkBRdata:[355, 275, 290, 265, 280],
    // 软工报录比
    rgBRdata:[355, 275, 290, 265, 280],
    // 电子报录比
    dzBRdata:[355, 275, 290, 265, 280],
  },


  onLoad: function (options) {
    var collegeid = options.collegeid;
    console.log("collegeid:"+collegeid);
    this.setData({
      collegeid:collegeid,
    })
    this.getcollegeBrochure();
    this.getGradeJK();  // 页面加载时调用计科历年分数
    this.getGradeRG()   // 软工历年分数
    this.getGradeDZ()   // 电子信息历年分数
    this.getJKBR();     // 计科报录比
    this.getRGBR();     // 软工报录比
    this.getDZBR();     // 电子报录比
  },


  getcollegeBrochure:function(){
    var mark = 'getcollegeBrochure';
    var collegeid = this.data.collegeid;
    wx.request({
      url: 'http://localhost:8080/youYanZaiXian/CollegeServlet',
      method: 'POST',
      data:{
        mark:mark,
        collegeid:collegeid,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json'
      },
      success: (res)=>{
        var cbList = res.data.data.cbList;
        this.setData({
          cbList:cbList,
        })
        //console.log(this.data.cbList)
      }
    });
  },


  // 图表
  // 获取计算机科学与技术历年分数
  getGradeJK:function(){
    var windowWidth = 320;
    try {
      var res = wx.getSystemInfoSync();
      windowWidth = res.windowWidth;
    } catch (e) {
      console.error('getSystemInfoSync failed!');
    }
    yuelineChart = new wxCharts({ //当月用电折线图配置
      canvasId: 'getGradeJK',
      type: 'line',
      categories: ['2021', '2020', '2019', '2018', '2017'], //categories X轴
      animation: true,
      // background: '#f5f5f5',
      series: [{
        name: '计算机科学与技术',
        data: this.data.jkGradeData,
        format: function (val, name) {
          return val.toFixed(2) + 'kWh';
        }
      }, 
     
    ],
      xAxis: {
        disableGrid: true
      },
      yAxis: {
        title: '历年录取分数',
        format: function (val) {
          return val.toFixed(2);
        },
        max: 20,
        min: 0
      },
      width: windowWidth,
      height: 200,
      dataLabel: false,
      dataPointShape: true,
      extra: {
        lineStyle: 'curve'
      }
    });
  },

   // 获取软件工程历年分数
   getGradeRG:function(){
    var windowWidth = 320;
    try {
      var res = wx.getSystemInfoSync();
      windowWidth = res.windowWidth;
    } catch (e) {
      console.error('getSystemInfoSync failed!');
    }
    yuelineChart = new wxCharts({ //当月用电折线图配置
      canvasId: 'getGradeRG',
      type: 'line',
      categories: ['2021', '2020', '2019', '2018', '2017'], //categories X轴
      animation: true,
      // background: '#f5f5f5',
      series: [{
        name: '软件工程',
        data: this.data.rgGradeData,
        format: function (val, name) {
          return val.toFixed(2) + 'kWh';
        }
      }, 
    ],
      xAxis: {
        disableGrid: true
      },
      yAxis: {
        title: '历年录取分数',
        format: function (val) {
          return val.toFixed(2);
        },
        max: 20,
        min: 0
      },
      width: windowWidth,
      height: 200,
      dataLabel: false,
      dataPointShape: true,
      extra: {
        lineStyle: 'curve'
      }
    });
  },

  // 获取电子信息历年分数
  getGradeDZ:function(){
    var windowWidth = 320;
    try {
      var res = wx.getSystemInfoSync();
      windowWidth = res.windowWidth;
    } catch (e) {
      console.error('getSystemInfoSync failed!');
    }
    yuelineChart = new wxCharts({ //当月用电折线图配置
      canvasId: 'getGradeDZ',
      type: 'line',
      categories: ['2021', '2020', '2019', '2018', '2017'], //categories X轴
      animation: true,
      // background: '#f5f5f5',
      series: [{
        name: '电子信息',
        data: this.data.dzGradeData,
        format: function (val, name) {
          return val.toFixed(2) + 'kWh';
        }
      }, 
    ],
      xAxis: {
        disableGrid: true
      },
      yAxis: {
        title: '历年录取分数',
        format: function (val) {
          return val.toFixed(2);
        },
        max: 20,
        min: 0
      },
      width: windowWidth,
      height: 200,
      dataLabel: false,
      dataPointShape: true,
      extra: {
        lineStyle: 'curve'
      }
    });
  },

  // 计科报录比
  getJKBR:function(){
    var windowWidth = 320;
    try {
      var res = wx.getSystemInfoSync();
      windowWidth = res.windowWidth;
    } catch (e) {
      console.error('getSystemInfoSync failed!');
    }
    yuelineChart = new wxCharts({ //当月用电折线图配置
      canvasId: 'getJKBR',
      type: 'line',
      categories: ['2021', '2020', '2019', '2018', '2017'], //categories X轴
      animation: true,
      // background: '#f5f5f5',
      series: [{
        name: '计算机科学与技术',
        data: this.data.jkBRdata,
        format: function (val, name) {
          return val.toFixed(2) + 'kWh';
        }
      }, 
      
    ],
      xAxis: {
        disableGrid: true
      },
      yAxis: {
        title: '历年报录比',
        format: function (val) {
          return val.toFixed(2);
        },
        max: 20,
        min: 0
      },
      width: windowWidth,
      height: 200,
      dataLabel: false,
      dataPointShape: true,
      extra: {
        lineStyle: 'curve'
      }
    });
  },

  // 软工报录比
  getRGBR:function(){
    var windowWidth = 320;
    try {
      var res = wx.getSystemInfoSync();
      windowWidth = res.windowWidth;
    } catch (e) {
      console.error('getSystemInfoSync failed!');
    }
    yuelineChart = new wxCharts({ //当月用电折线图配置
      canvasId: 'getRGBR',
      type: 'line',
      categories: ['2021', '2020', '2019', '2018', '2017'], //categories X轴
      animation: true,
      // background: '#f5f5f5',
      series: [{
        name: '软件工程',
        data: this.data.rgBRdata,
        format: function (val, name) {
          return val.toFixed(2) + 'kWh';
        }
      }, 
      
    ],
      xAxis: {
        disableGrid: true
      },
      yAxis: {
        title: '历年报录比',
        format: function (val) {
          return val.toFixed(2);
        },
        max: 20,
        min: 0
      },
      width: windowWidth,
      height: 200,
      dataLabel: false,
      dataPointShape: true,
      extra: {
        lineStyle: 'curve'
      }
    });
  },

  // 电子报录比
  getDZBR:function(){
    var windowWidth = 320;
    try {
      var res = wx.getSystemInfoSync();
      windowWidth = res.windowWidth;
    } catch (e) {
      console.error('getSystemInfoSync failed!');
    }
    yuelineChart = new wxCharts({ //当月用电折线图配置
      canvasId: 'getDZBR',
      type: 'line',
      categories: ['2021', '2020', '2019', '2018', '2017'], //categories X轴
      animation: true,
      // background: '#f5f5f5',
      series: [{
        name: '电子信息',
        data: this.data.rgBRdata,
        format: function (val, name) {
          return val.toFixed(2) + 'kWh';
        }
      }, 
    ],
      xAxis: {
        disableGrid: true
      },
      yAxis: {
        title: '历年报录比',
        format: function (val) {
          return val.toFixed(2);
        },
        max: 20,
        min: 0
      },
      width: windowWidth,
      height: 200,
      dataLabel: false,
      dataPointShape: true,
      extra: {
        lineStyle: 'curve'
      }
    });
  },

  
  switchTab: function(e){
    this.setData({
      currentNavtab: e.currentTarget.dataset.idx
    });
  },

  // 跳转到回答页面
  bindItemTap: function() {
    wx.navigateTo({
      url: '../answer/answer'
    })
  },
  // 跳转到问题页面
  bindQueTap: function() {
    wx.navigateTo({
      url: '../question/question'
    })
  },


  goEnrollmenmtGuide:function(e){
    var cb = e.currentTarget.dataset.cb
    //console.log(cb)
    var cbJson = JSON.stringify(cb);
    wx.navigateTo({
      url: '/pages/college/enrollmentGuide/enrollmentGuide?cb='+cbJson,
    })
  }



});


